
<div class="easyui-layout" data-options="fit:true"  style="margin:5px">
    <!-- Begin of toolbar -->
    <div data-options="region:'center',border:false">
    <!-- Begin of 工具条 -->
    <div id="session-toolbar"  style="margin:5px">
        <div>
            <a href="javascript:;" class="easyui-linkbutton" iconCls="icon-cancel" onclick="lockUser()" plain="false">强制踢出</a>
        </div>
    </div>
    <!-- end of 工具条-->
	<table id="session-datagrid"></table>
    </div>
</div>

<!-- End of 新增、编辑 -->
<script type="text/javascript">

	$(function(){
		//搜索
		$("#session-search").click(function(){
			$("#session-datagrid").datagrid('load', {
				userName: $("#uname").val(),
				mobileNum: $("#tel").val(),
				startDate: $("#date_s").val(),
				endDate:	$("#date_e").val()
			});
		});
	})
	/**
	* 
	*/
	function lockUser(){
		var items = $('#session-datagrid').datagrid('getSelections');
		if(items.length ==1){
			$.messager.confirm('信息提示','确定要踢出该用户？', function(result){
				if(result){
					$.ajax({
						url:'sessions/'+items[0].id+'/forceLogout',
						data:{},
						success:function(data){
							if(data){
								$.messager.alert('信息提示','踢出成功！','info');		
								$('#session-datagrid').datagrid('reload');  
							}
							else
							{
								$.messager.alert('信息提示','踢出失败！','info');		
							}
						}	
					});
				}	
			});
		}else{
			$.messager.alert('信息提示','请选择一条记录！','info');		
		}
	}

	/**
	* 载入数据
	*/
	$("#session-datagrid").datagrid({
		url:'sessions/list',
		rownumbers:true,
		singleSelect:false,
		pageSize:30,           
		pagination:true,
		multiSort:true,
		fitColumns:true,
		fit:true,
		toolbar: "#session-toolbar",
		columns:[[
			{ field:'currName',title:'用户名',width:100},
			{ field:'id',title:'会话ID',width:180},
			{ field:'host',title:'IP',width:100},
			{ field:'lastAccessTime',title:'最后活跃时间',width:100,
				formatter: function(value,row,index){
					return  row.lastAccessTime;
				}		
			},
			{ field:'isKickedOut',title:'是否被踢出',width:100,			
				formatter: function(value,row,index){
					if (value){
						return "<font color='#d15b47'>是</font>";
					} else {
						return "否";
					}
				}
			}
		]]
	});
</script>
